package dao.impl;

import dao.UserDao;
import org.apache.ibatis.session.SqlSession;
import pojo.User;
import utils.MyBatisUtil;

import java.util.List;

public class UserDaoImpl implements UserDao {
    @Override
    public List<User> findAll(User user) {
        return MyBatisUtil.getSession().getMapper(UserDao.class).findAll(user);
    }
        public int addUser(User user){
            SqlSession session = MyBatisUtil.getSession();
            int result = session.getMapper(UserDao.class).addUser(user);
            session.commit();
            return result;
        }
        @Override
        public User findUserById(int id){
        return MyBatisUtil.getSession().getMapper(UserDao.class).findUserById(id);
        }
        @Override
        public int updateUser(User user){
        SqlSession session = MyBatisUtil.getSession();
        int result = session.getMapper(UserDao.class).updateUser(user);
        session.commit();
        return result;
        }


    @Override
        public int deleteUserById(int id){
            SqlSession session = MyBatisUtil.getSession();
            int result = session.getMapper(UserDao.class).deleteUserById(id);
            session.commit();
            return result;
        }

    }

